//
//  NeedButSelectView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/5.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "NeedButSelectView.h"

@implementation NeedButSelectView

-(id)initWithFrame:(CGRect)aFrame inSuperView:(UIView *)aSuperView{
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [UIColor whiteColor];
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self);
            make.height.equalTo(@1);
        }];
        NSArray * titleArr = @[@"普通",@"图片",@"极速",@"定金",@"全部求购"];
        for (int i=1; i<6; i++) {
            CGFloat butWidth = kWidthProportion_In_iPhoneTriploid(52);
            CGFloat x_width = 0;
            if (i == 5) {
                x_width = butWidth*4+kWidthProportion_In_iPhoneTriploid(80);
                butWidth = kWidthProportion_In_iPhoneTriploid(80);
            }else{
                x_width = butWidth*i;
            }
            x_width = x_width + kWidthProportion_In_iPhoneTriploid(10)*(i-1);
            GLGWButton * topBut = [[GLGWButton alloc] initWithFrame:CGRectMake(KScreenWidth - kWidthProportion_In_iPhoneTriploid(22)-x_width, kHeightProportion_In_iPhoneTriploid(16), butWidth, kHeightProportion_In_iPhoneTriploid(30)) hTitle:titleArr[i-1] titleLableFont:SYSTEMFONT(14) titleLableColor:kColor_Rule_Yellow theCornerRadius:kHeightProportion_In_iPhoneTriploid(15) theBorderWidth:1.0 theBorderColor:kColor_Rule_Yellow backgroundColr:[UIColor whiteColor] inSuperView:self];
            topBut.tag = 130+i;
            [topBut addTarget:self action:@selector(topSelect:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return self;
}

-(void)topSelect:(GLGWButton *)sender{
    sender.backgroundColor = kColor_Rule_Yellow;
    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    for (int j=0; j<5; j++) {
        GLGWButton * but = (GLGWButton *)[self viewWithTag:131+j];
        if (sender != but) {
            but.backgroundColor = [UIColor whiteColor];
            [but setTitleColor:kColor_Rule_Yellow forState:UIControlStateNormal];
        }
    }
    if (self.Block_TopAction) {
        self.Block_TopAction(sender);
    }
}

@end
